//TODO: java版临时注释 自动引用暂不提供
//package com.inspur.edp.udt.generator.config;
//
//import Inspur.Ecp.Caf.Common.*;
//import Inspur.Gsp.Lcm.Metadata.Api.*;
//import Inspur.Ecp.Caf.ServiceMgr.*;
//import Inspur.Gsp.Lcm.CloudDev.FS.Api.*;
//import Inspur.Gsp.Udt.DesignTime.Api.Entity.*;
//import Inspur.Gsp.Cef.Generator.Common.*;
//import Inspur.Gsp.Cef.Generator.Overall.*;
//import com.inspur.edp.cef.generator.overall.CefGeneratorContext;
//import com.inspur.edp.udt.designtime.api.entity.UnifiedDataTypeDef;
//
////TODO: 框架引用可以整个工程只加一次, 将来再完善
//public class ProjectRefGenerator
//{
//	private UnifiedDataTypeDef udt;
//	private GspMetadata metadata;
//	private CefGeneratorContext context;
//	private static final String defaultNugetVersion = "*";
//
//	private String projPath;
//	private String projFolderPath;
//	//private readonly string binPath;
//	private IFsService fsService = ServiceManager.<IFsService>GetService();
//	public ProjectRefGenerator(CefGeneratorContext context)
//	{
//		//this.metadata = metadata;
//		this.context = context;
//		//udt = metadata.Content as UnifiedDataTypeDef;
//		//var metadataProj = ServiceManager.GetService<IMetadataProjectService>().GetMetadataProjInfo(metadata.RelativePath);
//		//projFolderPath = metadataProj.ProjectPath;
//		//projPath = Path.Combine(projFolderPath, metadataProj.ProjectFileName);
//	}
//
//	public final void Generate()
//	{
//		ProjectRefHandler handler = new ProjectRefHandler(context.Metadata.RelativePath);
//		//添加引用
//		handler.AddReference();
//		//XmlDocument doc = LoadProjectDocument(metadata.RelativePath);
//		//  DeleteFrameDllReferences(doc);
//		AddFrameworkReferences(handler);
//		AddGenDllReferences(handler);
//		handler.Save();
//		//TODO: 占内存待完善
//		//SaveProjectDocument(doc);
//		//  AddFrameWorkReference();
//
//	}
//
//	private void SaveProjectDocument(XmlDocument doc)
//	{
//		MemoryStream stream = new MemoryStream();
//		doc.Save(stream);
//		stream.Seek(0, SeekOrigin.Begin);
//		fsService.Update(projPath, stream);
//	}
//
//	private XmlDocument LoadProjectDocument()
//	{
//		XmlDocument doc = new XmlDocument();
//		if (!fsService.ExistsAsFile(projPath))
//		{
//			throw new RuntimeException("元数据工程不存在");
//		}
////C# TO JAVA CONVERTER NOTE: The following 'using' block is replaced by its Java equivalent:
////C# TO JAVA CONVERTER TODO TASK: There is no equivalent to implicit typing in Java:
////		using (var projStream = fsService.Read(projPath))
//		var projStream = fsService.Read(projPath);
//		try
//		{
//			doc.Load(projStream);
//		}
//		finally
//		{
//			projStream.dispose();
//		}
//
//		return doc;
//	}
//
////C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//		///#region dllReference(api/entity)
//	private void AddGenDllReferences(ProjectRefHandler handler)
//	{
//		AddOrUpdateDllReference(handler, $"bin\\{context.RefProjectGenerator.AssemblyName}.dll");
//	}
//
//	private void AddOrUpdateDllReference(ProjectRefHandler handler, String path)
//	{
//		handler.AddReference(path);
//	}
////C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//		///#endregion
//
//	//private string GetReferencePath(string assemblyName, string relativeAssemblyPath)
//	//{
//	//    //return Path.Combine("bin/ref", assemblyName + ".dll");
//	//    //return Path.Combine(Path.GetRelativePath(projFolderPath, relativeAssemblyPath), assemblyName + ".dll");
//	//    string rootPath;
//	//    //return string.Empty;
//	//    if (relativeAssemblyPath.EndsWith("bin"))
//	//        rootPath = "bin";
//	//    else
//	//        rootPath = "bin/ref";
//	//    return Path.Combine(rootPath, assemblyName + ".dll");
//	//}
//
//	//private void AddDllRef(XmlDocument doc, string assemblyName, string relativeAssemblyPath)
//	//{
//	//    var hintPath = doc.CreateElement("HintPath");
//	//    hintPath.InnerText = GetReferencePath(assemblyName, relativeAssemblyPath);
//	//    var reference = doc.CreateElement("Reference");
//	//    reference.SetAttribute("Include", assemblyName);
//	//    reference.AppendChild(hintPath);
//	//    var itemGroup = doc.CreateElement("ItemGroup");
//	//    itemGroup.AppendChild(reference);
//	//    doc.DocumentElement.AppendChild(itemGroup);
//	//}
//
//
//	//private void AddFrameWorkReference()
//	//{
//	//    IMetadataCompileService service = ServiceManager.GetService<IMetadataCompileService>();
//	//    service.UpdateProjRefs(projFolderPath, "Inspur.Gsp.Common.All", defaultNugetVersion);
//	//}
//
//	//private void DeleteFrameDllReference(XmlDocument doc, string assemblyName)
//	//{
//	//    var node = doc.SelectSingleNode(string.Format("//ItemGroup/Reference[@Include='{0}']", assemblyName));
//	//    if (node == null)
//	//        return;
//	//    var parentNode = node.ParentNode;
//	//    var grandNode = parentNode.ParentNode;
//	//    parentNode.RemoveAll();
//	//    grandNode.RemoveChild(parentNode);
//
//	//}
//
//	//private void DeleteFrameDllReferences(XmlDocument doc)
//	//{
//	//    DeleteFrameDllReference(doc, "Inspur.Gsp.Udt.api");
//	//    DeleteFrameDllReference(doc, "Inspur.Gsp.Udt.entity");
//	//    DeleteFrameDllReference(doc, "Inspur.Gsp.Udt.Spi");
//	//    DeleteFrameDllReference(doc, "Inspur.Gsp.Cef.entity");
//	//    DeleteFrameDllReference(doc, "Inspur.Gsp.Cef.api");
//	//    DeleteFrameDllReference(doc, "Inspur.Gsp.Cef.Spi");
//	//}
//
//	private static final String frameworkRefDir = "ref";
//	private void AddFrameworkReferences(ProjectRefHandler handler)
//	{
////C# TO JAVA CONVERTER TODO TASK: There is no equivalent to implicit typing in Java:
//		var refPath = Path.Combine(ServiceManager.<IMetadataService>GetService().GetRefPath(context.Metadata.RelativePath), frameworkRefDir);
//		if (!fsService.ExistsAsDir(refPath))
//		{
//			fsService.CreateDir(refPath);
//		}
//
//		AddFrameworkReference(handler, "Inspur.Gsp.Udt.api", refPath);
//		AddFrameworkReference(handler, "Inspur.Gsp.Udt.Spi", refPath);
//		AddFrameworkReference(handler, "Inspur.Gsp.Udt.entity", refPath);
//		AddFrameworkReference(handler, "Inspur.Gsp.Cef.api", refPath);
//		AddFrameworkReference(handler, "Inspur.Gsp.Cef.Spi", refPath);
//		AddFrameworkReference(handler, "Inspur.Gsp.Cef.entity", refPath);
//	}
//
//	private void AddFrameworkReference(ProjectRefHandler handler, String nugetName, String relativeAssemblyPath)
//	{
////C# TO JAVA CONVERTER TODO TASK: There is no equivalent to implicit typing in Java:
//		var dstFilePath = Path.GetFullPath(Path.Combine(PathTransform.GetUserProjectsRoot(), relativeAssemblyPath, String.Concat(nugetName, ".dll")));
////C# TO JAVA CONVERTER TODO TASK: There is no equivalent to implicit typing in Java:
//			var srcFilePath = Path.Combine(GspEnvironment.RootPath, "platform/common/libs", String.Concat(nugetName, ".dll"));
//			File.Copy(srcFilePath, dstFilePath,true);
//		AddOrUpdateDllReference(handler, $@"bin\ref\{nugetName}.dll");
//	}
//}